<!DOCTYPE html>
<html>
<head>
    <title>文件上传</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-btn-container">
            <form class="layui-form layui-form-pane" action="">
                <button class="layui-btn" lay-submit lay-filter="config-btn"><i class="layui-icon layui-icon-set"></i> 存储配置 </button>
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="upload-btn"><i class="layui-icon layui-icon-upload"></i> 上传文件 </button>
            </form>
        </div>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<script type="text/html" id="currentTableBar">
    <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script type="text/javascript">
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: serverUrl('oss/file/list'),
            defaultToolbar: [],
            cols: [[
                {type: "numbers", width: 80, title: '序号'},
                {field: 'id', width: 150, title: '文件ID'},
                {field: 'url', title: '文件URL'},
                {field: 'url', width: 150, title: '预览', templet: function (d) {
                    return '<img src="'+d.url+'" alt=""/>';
                }},
                {field: 'createDate', width: 200, title: '创建时间'},
                {title: '操作', width: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [15, 30, 50],
            limit: 15,
            page: true
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('确定删除ID '+data.id+' 文件吗？', function (index) {
                    deleteTableRow('oss/file/delete', [data.id], function (rs) {
                        obj.del();
                    });
                    layer.close(index);
                });
            }
        });

        form.on('submit(config-btn)', function (data) {
            openFormView('oss/file/config.html', '存储配置');
            return false;
        });
        form.on('submit(upload-btn)', function (data) {
            layer.open({
                title: '上传文件',
                type: 2,
                shade: 0.5,
                maxmin:true,
                shadeClose: true,
                area: ['75%', '70%'],
                content: serverUrl('oss/file/upload.html')
            });
            return false;
        });

    });
</script>

</body>
</html>